import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { BaseItem } from "../common/BaseItem";
import { GTextFormat } from "../../../common/GTextFormat";
import { ImagesConst } from "../../resource/ImagesConst";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ArenaGiftData } from "./ArenaGiftData";
import { ItemData } from "../../resource/info/ItemData";
import { ObjectPool } from "../../../../com/gengine/utils/pools/ObjectPool";
import { GButton } from "../../../../com/mui/controls/GButton";
import { SArenaGiftBagItem } from "../../../../Message/Game/SArenaGiftBagItem";
//class ArenaGiftRender
    
    export  class ArenaGiftRender /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.createChildren();
            return;
        }

        /* internal  */createChildren(): void
        {
            this._bg = GlobalClass.getBitmap("PropBg");
            this._bg.x = 0;
            this._bg.y = 0;
            this.addChild(this._bg);
            this._propItem = new BaseItem();
            this._propItem.isDragAble = false;
            this._propItem.label = "";
            this._propItem.move(5, 5);
            this._propItem.setAmountLabelPos(0, 35);
            var loc1=new GTextFormat();
            loc1.align = flash.text.TextFormatAlign.RIGHT;
            loc1.color = 16777215;
            loc1.size = 18;
            this._propItem.setAmountLabelFormat(loc1);
            this.addChild(this._propItem);
            this._removeBmp = GlobalClass.getBitmap(ImagesConst.ArenaGiftBagRemove);
            this._removeBmp.x = 5;
            this._removeBmp.y = 5;
            this._removeBmp.visible = false;
            this.addChild(this._removeBmp);
            this._btnRemove = ObjCreate.createGButton(Language.getString(43108), 10, 70, 52, 22, this);
            this._btnRemove.drawNow();
            this._btnRemove.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnRemoveClick);
            this._tfHasRemove = ObjCreate.createTextField(Language.getString(43109), 15, 73, 60, 20, this, GlobalStyle.textFormat6);
            this._tfHasRemove.visible = false;
            return;
        }

        /* internal  */onBtnRemoveClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._giftbagItem) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaGiftRemove, this._giftbagItem));
            }
            return;
        }

        public get arenaGiftData(): ArenaGiftData
        {
            return this._arenaGiftData;
        }

        public set data(arg1: Object)
        {
            if (typeof !arg1 === "arenagiftdata") 
            {
                return;
            }
            this._arenaGiftData = arg1 as ArenaGiftData;
            var loc1=this._arenaGiftData.giftBagItem;
            this._giftbagItem = loc1;
            if (loc1 == null) 
            {
                this._propItem.visible = false;
                this._btnRemove.visible = false;
                this._bg.visible = false;
                this._removeBmp.visible = true;
                this._tfHasRemove.visible = false;
                return;
            }
            this._propItem.visible = true;
            this._btnRemove.visible = true;
            this._bg.visible = true;
            this._removeBmp.visible = false;
            this._tfHasRemove.visible = false;
            if (loc1.remove) 
            {
                this._btnRemove.visible = false;
                this._propItem.visible = false;
                this._bg.visible = false;
                this._removeBmp.visible = true;
                this._tfHasRemove.visible = true;
            }
            else 
            {
                this._btnRemove.visible = true;
                this._propItem.visible = true;
                this._bg.visible = true;
                this._removeBmp.visible = false;
                this._tfHasRemove.visible = false;
            }
            if (this._arenaGiftData.isHaveSelected) 
            {
                this._btnRemove.visible = false;
            }
            if (this._arenaGiftData.isThisSelected) 
            {
                this.showLightMask();
            }
            else 
            {
                this.hideLightMask();
            }
            this._btnRemove.drawNow();
            this._propItem.itemData = new ItemData(loc1.itemCode);
            this._propItem.drawNow();
            this._propItem.amount = loc1.num;
            this._propItem.setSize(60, 60);
            return;
        }

        public set selected(arg1: Boolean)
        {
            if (arg1) 
            {
                this._bg.bitmapData = GlobalClass.getBitmapData("arenaGiftSelectBg");
            }
            else 
            {
                this._bg.bitmapData = GlobalClass.getBitmapData("PropBg");
            }
            return;
        }

        public showLightMask(): void
        {
            if (!this._lightMask) 
            {
                this._lightMask = ObjectPool.getObject(LightMask);
                this._lightMask.transform.matrix = new Object /* flash.geom.Matrix */();
                this._lightMask.x = 2;
                this._lightMask.y = 2;
                this._lightMask.scaleX = 79 / 42.5;
                this._lightMask.scaleY = 79 / 42.5;
                this.addChild(this._lightMask);
            }
            return;
        }

        public hideLightMask(): void
        {
            if (this._lightMask) 
            {
                if (this._lightMask.parent) 
                {
                    this._lightMask.parent.removeChild(this._lightMask);
                }
                this._lightMask.x = 0;
                this._lightMask.y = 0;
                this._lightMask.width = 40;
                this._lightMask.height = 40;
                this._lightMask = null;
            }
            return;
        }

        public get item(): BaseItem
        {
            return this._propItem;
        }

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_propItem: BaseItem;

        /* internal */ /* var */_tfHasRemove: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnRemove: GButton;

        /* internal */ /* var */_removeBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_giftbagItem: SArenaGiftBagItem;

        /* internal */ /* var */_arenaGiftData: ArenaGiftData;

        /* internal */ /* var */_lightMask: LightMask;
    }
